using Senparc.Weixin.Open.Entities;
using System;
namespace Senparc.Weixin.Open.CommonAPIs
{
	public class CommonApi
	{
		public static ComponentAccessTokenResult GetComponentAccessToken(string componentAppId, string componentAppSecret, string componentVerifyTicket, int timeOut = 10000)
		{
			string urlFormat = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";
			var data = new
			{
				component_appid = componentAppId,
				component_appsecret = componentAppSecret,
				component_verify_ticket = componentVerifyTicket
			};
			return CommonJsonSend.Send<ComponentAccessTokenResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut);
		}
		public static PreAuthCodeResult GetPreAuthCode(string componentAppId, string componentAppSecret, string componentVerifyTicket, int timeOut = 10000)
		{
			string arg = ComponentAccessTokenContainer.TryGetToken(componentAppId, componentAppSecret, componentVerifyTicket, false);
			string urlFormat = string.Format("https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token={0}", arg);
			var data = new
			{
				component_appid = componentAppId
			};
			return CommonJsonSend.Send<PreAuthCodeResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut);
		}
	}
}
